package com.emex.app.stuff.gui.model.renderer;

import com.emex.app.shared.data.Position;
import java.awt.Color;
import java.awt.Component;
import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author Sergey Karavaev
 */
public class ConfirmedPositionTableRendedEditor extends AbstractCellEditor implements TableCellEditor {

    private JSpinner editSpinner, renderSpinner;
    private Border originalBorder;

    public ConfirmedPositionTableRendedEditor() {
        editSpinner = new JSpinner();
        renderSpinner = new JSpinner();
        originalBorder = editSpinner.getBorder();
        editSpinner.setBorder(new LineBorder(Color.BLUE));
    }

    @Override
    public Object getCellEditorValue() {
        return editSpinner.getValue();
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        if (value != null) {
            editSpinner.setValue(value);
        } else {
            editSpinner.setValue(0);
        }
        return editSpinner;
    }

    private SpinnerNumberModel getJSpinnerModel(Position position) {
        SpinnerNumberModel model = new SpinnerNumberModel(1.0, 1.0, position.getAmount().doubleValue(), 1.0);
        return model;
    }
}
